<template>
  <div class="container">
    <h1>Electron + Vue 3 + TypeScript</h1>
    <div class="platform-info">
      <p>
        运行在: <strong>{{ platform }}</strong>
      </p>
      <p>
        Electron 版本: <strong>{{ electronVersion }}</strong>
      </p>
      <p>
        Node.js 版本: <strong>{{ nodeVersion }}</strong>
      </p>
      <p>
        Chrome 版本: <strong>{{ chromeVersion }}</strong>
      </p>
    </div>

    <div class="counter">
      <button @click="decrement">-</button>
      <span>{{ count }}</span>
      <button @click="increment">+</button>
    </div>

    <div class="features">
      <div
        v-for="(feature, index) in features"
        :key="index"
        class="feature-card"
      >
        <h3>{{ feature.title }}</h3>
        <p>{{ feature.description }}</p>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from "vue";

export default defineComponent({
  setup() {
    const count = ref(0);
    const platform = ref("");
    const electronVersion = ref("");
    const nodeVersion = ref("");
    const chromeVersion = ref("");

    const features = ref([
      { title: "Vite", description: "下一代前端开发与构建工具" },
      { title: "Vue 3", description: "渐进式 JavaScript 框架" },
      { title: "TypeScript", description: "JavaScript 的超集" },
      { title: "Electron", description: "使用 Web 技术构建跨平台桌面应用" },
    ]);

    const increment = () => count.value++;
    const decrement = () => count.value--;

    onMounted(() => {
      // 从 Electron 获取平台信息
      // if (window.electronAPI) {
      //   window.electronAPI.getPlatform().then((p: string) => {
      //     platform.value = p;
      //   });
      // }

      // 获取环境信息
      electronVersion.value = process.versions.electron || "N/A";
      nodeVersion.value = process.versions.node;
      chromeVersion.value = process.versions.chrome;
    });

    return {
      count,
      platform,
      electronVersion,
      nodeVersion,
      chromeVersion,
      features,
      increment,
      decrement,
    };
  },
});
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body {
  background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
  color: white;
  min-height: 100vh;
  padding: 20px;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 30px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
}

h1 {
  text-align: center;
  margin-bottom: 30px;
  font-size: 2.5rem;
  color: #fdbb2d;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.platform-info {
  background: rgba(255, 255, 255, 0.1);
  padding: 20px;
  border-radius: 15px;
  margin-bottom: 30px;
}

.platform-info p {
  margin: 10px 0;
  font-size: 1.1rem;
}

.counter {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin: 30px 0;
}

.counter button {
  padding: 12px 24px;
  font-size: 1.5rem;
  background: #4caf50;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.counter button:hover {
  background: #45a049;
  transform: translateY(-2px);
}

.counter span {
  font-size: 2rem;
  min-width: 60px;
  text-align: center;
  font-weight: bold;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 30px;
}

.feature-card {
  background: rgba(255, 255, 255, 0.1);
  padding: 20px;
  border-radius: 15px;
  transition: transform 0.3s, box-shadow 0.3s;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  background: rgba(255, 255, 255, 0.15);
}

.feature-card h3 {
  color: #fdbb2d;
  margin-bottom: 10px;
  font-size: 1.3rem;
}

.feature-card p {
  line-height: 1.5;
}
</style>